package cn.edu.ctbu.myblog.webapi;

import cn.edu.ctbu.myblog.domain.CommentDO;
import cn.edu.ctbu.myblog.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("webapi/blog/comment")
public class CommentController {

    @Autowired
    CommentService commentService;


    @RequestMapping("/list")
    public List<CommentDO> getAll(){

        List<CommentDO> commentDOS=commentService.getAll();
        return  commentDOS;

    }

    @GetMapping("/insert")
    public void addComment(HttpServletRequest htttprequest,String comment, int articleId){
        HttpSession session=htttprequest.getSession();
        int userId=(int)session.getAttribute("userId");
        commentService.addComment(comment,userId,articleId);
    }

}
